package com.itheima.web;

import com.itheima.dto.DishDto;

import com.itheima.pojo.Category;
import com.itheima.pojo.Dish;
import com.itheima.result.R;
import com.itheima.service.DishDtoService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 斌
 * @DateTime: 2023年02月06日  22:37:29
 * @Description: com.itheima.web
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishDtoService dishDtoService;

    @GetMapping("/page")
    public R selectDish(Integer page, Integer pageSize, DishDto dishDto){
        return dishDtoService.selectDish(page,pageSize,dishDto);
    }

    @PostMapping()
    public R saveDish(@RequestBody DishDto dishDto){
        return dishDtoService.saveDish(dishDto);
    }

    @GetMapping("/{id}")
    public R queryById(@PathVariable Long id){
        return dishDtoService.queryById(id);
    }
    @PutMapping()
    public R updateDish(@RequestBody DishDto dishDto){
       return dishDtoService.updateDish(dishDto);
    }
    @DeleteMapping()
    public R deleteDish(@RequestParam("ids") List<String> ids){
       return dishDtoService.deleteDish(ids);
    }
    @PostMapping("/status/{code}")
    public R updateStatus(@PathVariable Integer code,@RequestParam("ids") List<Long> ids){
        log.info("状态码：{}",code);
        return dishDtoService.updateStatus(code,ids);
    }
    @GetMapping("/list")
    public R listDish(DishDto dish){
      return   dishDtoService.listDish(dish);
    }

}
